package com.bing.bingPro.controller.tietong;

import cn.hutool.core.bean.BeanUtil;
import com.bing.bingPro.ExcelUtil;
import com.bing.bingPro.common.BaseResult;
import com.bing.bingPro.controller.dto.TOrderDateDTO;
import com.bing.bingPro.controller.dto.TTtComplainStatsProvinceDto;
import com.bing.bingPro.controller.vo.TTtComplainStatsCityVo;
import com.bing.bingPro.controller.vo.TTtComplainStatsProvinceVo;
import com.bing.bingPro.service.TTtComplainStatsService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.stream.Collectors;

@RestController
public class TTtComplainStatsController {

    @Resource
    private TTtComplainStatsService tTtComplainStatsService;

    @PostMapping("/maintenanceProvince")
    public BaseResult<List<TTtComplainStatsCityVo>> maintenanceProvince(@RequestBody TTtComplainStatsProvinceDto tOrderYearDto) {
        return new BaseResult<>(this.tTtComplainStatsService.queryMaintenanceProvince(tOrderYearDto));
    }

    @PostMapping("/exportMaintenanceProvince")
    public void exportMaintenanceProvince(HttpServletResponse response, @RequestBody TTtComplainStatsProvinceDto tOrderYearDto) throws Exception {
        List<TTtComplainStatsCityVo> complainStatsProvinceVos = tTtComplainStatsService.exportMaintenance(tOrderYearDto);
        String monthOrProvinceTime = "铁通维护工单统计-省" + tOrderYearDto.getTime();
        ExcelUtil.writeExcel(response,
                complainStatsProvinceVos.stream().map(tTtComplainStatsProvinceVo -> {
                    TTtComplainStatsProvinceVo vo = new TTtComplainStatsProvinceVo();
                    BeanUtil.copyProperties(tTtComplainStatsProvinceVo, vo);
                    return vo;
                }).collect(Collectors.toList()),
                monthOrProvinceTime,
                "铁通维护工单统计-省" + tOrderYearDto.getTime(),
                TTtComplainStatsProvinceVo.class
        );
    }

    @PostMapping("/exportMaintenanceCity")
    public void exportMaintenanceCity(HttpServletResponse response, @RequestBody TTtComplainStatsProvinceDto tOrderYearDto) throws Exception {
        List<TTtComplainStatsCityVo> complainStatsProvinceVos = tTtComplainStatsService.exportMaintenance(tOrderYearDto);
        String monthOrDayTime = "铁通维护工单统计-市" + tOrderYearDto.getTime();
        ExcelUtil.writeExcel(response, complainStatsProvinceVos, monthOrDayTime, "铁通维护工单统计-市" + tOrderYearDto.getTime(), TTtComplainStatsCityVo.class);

    }

    @PostMapping("/dateListMaintenance")
    public BaseResult<List<String>> dateList(@RequestBody TOrderDateDTO tOrderDateDTO) {
        return new BaseResult<>(this.tTtComplainStatsService.dateList(tOrderDateDTO));
    }
}
